package com.xsjiong.jaript.lexer;

import java.lang.reflect.Field;

public class JSymbols {
	public static final byte Identifier = 0, Comma = 1, Integer = 2, EOF = 3, SingleLineComment = 4, MultiLineComment = 5, Plus = 6, Minus = 7, Multiplication = 8, Division = 9,
			Increase = 10, Decrease = 11, SelfPlus = 12, SelfMinus = 13, SelfMultiplication = 14, SelfDivision = 15, Equal = 16, Assignment = 17, Greater = 18,
			ShiftBitsRight = 19, UnsignedShiftBitsRight = 20, SelfShiftBitsRight = 21, GreaterOrEqual = 22, Less = 23, LessOrEqual = 24, ShiftBitsLeft = 25, SelfShiftBitsLeft = 26,
			BitwiseAnd = 27, And = 28, SelfBitwiseAnd = 29, BitwiseOr = 30, Or = 31, SelfBitwiseOr = 32, NotEqualTo = 33, Not = 34, Modulo = 35, SelfModulo = 36, BitwiseXor = 37, SelfBitwiseXor = 38,
			BitInversion = 39, LeftParenthesis = 40, RightParenthesis = 41, LeftBrace = 42, RightBrace = 43, Period = 44, Semicolon = 45, VariableArguments = 46, Colon = 47,
			LeftSquareBracket = 48, RightSquareBracket = 49;
	// 关键字 (50 - 102)
	public static final String[] _KEYWORDS = {
			"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "do",
			"double", "else", "enum", "extends", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof",
			"int", "interface", "long", "native", "new", "package", "private", "protected", "public", "return", "strictfp", "short",
			"static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "void", "volatile", "while",
			"true", "false", "null"
	};
	public static final byte String = 103, QuestionMark = 104, SelfUnsignedShiftBitsRight = 105;

	public static byte _GetKeywordIndex(String k) {
		if (k == null || k.length() == 0) return -1;
		for (byte i = 0; i < _KEYWORDS.length; i++)
			if (_KEYWORDS[i].equals(k)) return (byte) (i + 50);
		return -128;
	}

	public static String _GetSymbolName(byte i) {
		if (i >= 50 && i <= 102)
			return _KEYWORDS[i - 50];
		try {
			for (Field one : JSymbols.class.getFields())
				if (one.getType() == byte.class && one.getInt(null) == i) return one.getName();
		} catch (Throwable t) {
			return "Error: " + t.toString();
		}
		return "Undefined";
	}

	public static boolean _IsType(byte c) {
		return c == Identifier || c == 54 || c == 57 || c == 63 || c == 69 || c == 76 || c == 78 || c == 87;
	}
}
